package cn.wolfcode.business.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    //将字符串转换为日期
    public static Date parseDate(String time,String regex){
        if(time==null ||regex==null){
            return null;
        }
        SimpleDateFormat sdf=new SimpleDateFormat(regex);
        try {
            return sdf.parse(time);
        } catch (Exception e) {
            return null;
        }
    }

    //将日期转换为 字符串
    public static String Date2String(Date date,String regex){
        if(date==null||regex==null){
            return null;
        }

        SimpleDateFormat sdf=new SimpleDateFormat(regex);
        return sdf.format(date);
    }

// 日期计算
    public static Date changeDate (Date date,Integer type,Integer amout){

        //参数验证
        if(date==null||type==null||amout==null){
            return null;
        }
      Calendar calendar= Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(type,amout);
        return calendar.getTime();


    }

}
